//
//  HMMainViewController.swift
//  SinaWeibo
//
//  Created by Freakthen on 2016/12/6.
//  Copyright © 2016年 Freakthen. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        addChildViewController( HMHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController( HMMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController( HMDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController( HMProfileTableViewController(), imageName: "tabbar_profile", title: "我的")    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    // 重载添加子视图控制器
    func addChildViewController(_ childController: UIViewController,imageName: String, title: String) {
        // 设置tabbar图片
        childController.tabBarItem.image = UIImage(named: imageName)
        // 设置tabbar的图片的渲染模式
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .normal)
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 12)], for: .normal)
        // 合成一句
        childController.title = title
        
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
        
        
    }

}
